my_set = {"小明", "小红", "小刚", "小明", "小红", "小刚"}
my_set_enpty = set()
print(f"my_set的内容是：{my_set}，类型是{type(my_set)}")
print(f"my_set的内容是：{my_set_enpty}，类型是{type(my_set_enpty)}")

# add方法
my_set.add("python")
my_set.add("小明")
print(f"my_set添加元素后结果是：{my_set}")

# remove方法
my_set.remove("小刚")
print(f"my_set移除元素后结果是：{my_set}")


# pop方法
my_set = {"小明", "小红", "小刚"}
element = my_set.pop()
print(f"集合被取出元素是：{element}，取出元素后：{my_set}")


# clear方法
my_set.clear()
print(f"集合被清空了，结果是：{my_set}")

# 取两个集合的差集
set1 = {1,2,3}
set2 = {1,5,6}
set3 = set1.difference(set2)
print(set3)
print(set1)
print(set2)

# 消除两个集合的差集
set1 = {1,2,3}
set2 = {1,5,6}
set1.difference_update(set2)
print(set1)
print(set2)

# 2个集合合并
set1 = {1, 2, 3}
set2 = {1, 5, 6}
set4 = set1.union(set2)
print(f"合并后的集合为{set4}")


# 统计集合元素数量len()
set1 = {1, 2, 3, 4, 5, 1, 2, 3, 4, 5}
num = len(set1)
print(num)
# 集合的遍历
set1 = {1, 2, 3, 4, 5}
for element in set1:
    print(f"集合的元素有{element}")